'use strict';
var h = Object.defineProperty;
var g = (i, e, t) =>
  e in i
    ? h(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t })
    : (i[e] = t);
var p = (i, e, t) => (g(i, typeof e != 'symbol' ? e + '' : e, t), t);
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const o = require('../../nodes/identity.cjs'),
  a = require('../../nodes/Pair.cjs'),
  n = require('../../nodes/YAMLMap.cjs');
require('../../visit.cjs');
require('../../stringify/stringifyString.cjs');
const u = class u extends n.YAMLMap {
  constructor(e) {
    super(e), (this.tag = u.tag);
  }
  add(e) {
    let t;
    o.isPair(e)
      ? (t = e)
      : e &&
          typeof e == 'object' &&
          'key' in e &&
          'value' in e &&
          e.value === null
        ? (t = new a.Pair(e.key, null))
        : (t = new a.Pair(e, null)),
      n.findPair(this.items, t.key) || this.items.push(t);
  }
  get(e, t) {
    const s = n.findPair(this.items, e);
    return !t && o.isPair(s) ? (o.isScalar(s.key) ? s.key.value : s.key) : s;
  }
  set(e, t) {
    if (typeof t != 'boolean')
      throw new Error(
        `Expected boolean value for set(key, value) in a YAML set, not ${typeof t}`,
      );
    const s = n.findPair(this.items, e);
    s && !t
      ? this.items.splice(this.items.indexOf(s), 1)
      : !s && t && this.items.push(new a.Pair(e));
  }
  toJSON(e, t) {
    return super.toJSON(e, t, Set);
  }
  toString(e, t, s) {
    if (!e) return JSON.stringify(this);
    if (this.hasAllNullValues(!0))
      return super.toString(Object.assign({}, e, { allNullValues: !0 }), t, s);
    throw new Error('Set items must all have null values');
  }
  static from(e, t, s) {
    const { replacer: f } = s,
      c = new this(e);
    if (t && Symbol.iterator in Object(t))
      for (let l of t)
        typeof f == 'function' && (l = f.call(t, l, l)),
          c.items.push(a.createPair(l, null, s));
    return c;
  }
};
p(u, 'tag', 'tag:yaml.org,2002:set');
let r = u;
const m = {
  collection: 'map',
  identify: i => i instanceof Set,
  nodeClass: r,
  default: !1,
  tag: 'tag:yaml.org,2002:set',
  createNode: (i, e, t) => r.from(i, e, t),
  resolve(i, e) {
    if (o.isMap(i)) {
      if (i.hasAllNullValues(!0)) return Object.assign(new r(), i);
      e('Set items must all have null values');
    } else e('Expected a mapping for this tag');
    return i;
  },
};
exports.YAMLSet = r;
exports.set = m;
